﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Restaurant.BusinessEntity;

namespace Restaurant.Repository.Mapping
{
    public class VentaMap : EntityTypeConfiguration<Venta>
    {
        public VentaMap()
        {
            this.HasKey(r => r.Id);

            //propiedades
            this.Property(r => r.Id)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            this.Property(r => r.Fecha)
                .IsRequired();

            this.Property(r => r.SubTotal)
               .IsRequired();

            this.Property(r => r.IGV)
              .IsRequired();

            this.Property(r => r.Total)
              .IsRequired();

            this.Property(r => r.Soles)
              .IsOptional();

            this.Property(r => r.Dolares)
              .IsOptional();

            this.Property(r => r.Tarjeta)
              .IsOptional();

            this.Property(r => r.TipoComprobante)
              .IsRequired().HasMaxLength(50);

            //table
            this.ToTable("Venta");

            //Relaciones
            this.HasRequired(r => r.AperturaCaja)
                .WithMany(a=>a.Ventas)
                .HasForeignKey(r => r.IdApertura)
                .WillCascadeOnDelete(false);

            this.HasRequired(r => r.Cliente)
                .WithMany(a => a.Ventas)
                .HasForeignKey(r => r.IdCliente)
                .WillCascadeOnDelete(false);
        }

    }
}
